package com.xjtu.platform.security.emailConfirm.Impl;

import com.xjtu.platform.security.emailConfirm.EmailConfirmDto;
import com.xjtu.platform.security.emailConfirm.EmailConfirmService;
import com.xjtu.platform.security.emailConfirm.dao.EmailConfirmDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service
@Transactional
public class EmailConfirmServiceImpl implements EmailConfirmService {
    @Resource
    private EmailConfirmDao emailConfirmDao;

    @Override
    public boolean insertFlag( int code, String user_id) {
        try {
            emailConfirmDao.insertFlag(code,user_id);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public String getEmail(String user_id) {
        try {
            return emailConfirmDao.getEmail(user_id);
        }catch (Exception e){
            e.printStackTrace();
            return "error";
        }
    }

    @Override
    public boolean confirmCode(EmailConfirmDto emailConfirmDto) {
        try {
            int count = emailConfirmDao.confirmEmail(emailConfirmDto) ;
            return count>0;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean isUnique(EmailConfirmDto emailConfirmDto, String user_id) {
        try {
            int count = emailConfirmDao.isUnique(emailConfirmDto,user_id);
            return count > 0;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public String codeIdent(String user_id) {
        try {
            return emailConfirmDao.getFlag(user_id);
        }catch (Exception e){
            e.printStackTrace();
            return "error";
        }
    }
}
